/////////////////////////同步ajax调用
/**
 * 同步ajax调用 返回json Object
 * 
 * @param {}
 *            urlStr
 * @param {}
 *            paramsStr 为字符串键值对形式“key=value&key2=value2”
 * @return {} 返回json Object
 */
function ajaxSyncCall(urlStr, paramsStr) {
	var obj;
	var value;
	if (window.ActiveXObject) {
		obj = new ActiveXObject('Microsoft.XMLHTTP');
	} else if (window.XMLHttpRequest) {
		obj = new XMLHttpRequest();
	}
	obj.open('POST', urlStr, false);
	obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	obj.send(paramsStr);
	return obj.responseText;
} 

function getZtoInfo(id){//"200822524654"
	var resxml=ajaxSyncCall("oo.jsp?charset=GB2312&url=http://www.zto.cn/bill.aspx?id="+id);
	resxml=resxml.match(/<form name="aspnetForm"[\s\S]*form>/g)[0];
	//resxml=resxml.replace(/<noscript[\s\S]*noscript>/g,"") ; //过滤noscript
	//resxml=resxml.replace(/<script[\s\S]*script>/g,"") ; //过滤javascript
	//resxml=resxml.replace(/<style[\s\S]*style>/g,"") ; //过滤style
	//resxml=resxml.replace(/<\/tr>/g,"[1tr]") ;
	resxml=resxml.replace(/[\[\]]/g,"*");
	//resxml=resxml.replace(/\]/g,"*");
	resxml=resxml.replace(/<tr[^>]*>/g,"[tr]");
	resxml=resxml.replace(/<\/tr>/g,"[/tr]");
	resxml=resxml.replace(/<td[^>]*>/g,"[td]");
	resxml=resxml.replace(/<\/td>/g,"[/td]");
	resxml=resxml.replace(/<th[^>]*>/g,"[td]");
	resxml=resxml.replace(/<\/th>/g,"[/td]");
	resxml=resxml.replace(/<[^>]+>/g,"");
	//resxml=resxml.replace(/<[^>]+>/g,"");
	resxml=resxml.replace(/\[/g,"<");
	resxml=resxml.replace(/\]/g,">");
	return "<table>"+resxml+"</table>";
}
function getZtoInfo_json(id){//"200822524654"
	var resxml=ajaxSyncCall("oo.jsp?charset=GB2312&url=http://www.zto.cn/bill.aspx?id="+id);
	resxml=resxml.match(/<form name="aspnetForm"[\s\S]*form>/g)[0];
	resxml=resxml.replace(/[\n\s(&nbsp;)]/g,"");
	resxml=resxml.replace(/返回页头/g,":");
	//resxml=resxml.replace(/[\n\s]/g,"");
	var ss=resxml.match(/SORRY/g);
	if(ss&&ss.length>0){
		return {err:resxml.replace(/<[^>]+>/g,"")};
	}
	resxml=resxml.replace(/<tr[^>]*>/g,"[tr]");
	//resxml=resxml.replace(/<\/tr>/g,"[/tr]");
	resxml=resxml.replace(/<td[^>]*>/g,"[td]");
	//resxml=resxml.replace(/<\/td>/g,"[/td]");
//	resxml=resxml.replace(/<th[^>]*>/g,"[td]");
	//resxml=resxml.replace(/<\/th>/g,"[/td]");
	resxml=resxml.replace(/<[^>]+>/g,"");
	//alert("*"+resxml+"*")
	var resultJson={billno:"",records:[]};
	var  rowArr=resxml.split("[tr]");
	//处理单号
	resultJson.billno=rowArr[2].replace(/[(\[td\]),(:),(跟踪记录)]/g,"");
	
	for(var i=3;i<rowArr.length;i++)//第一行第二行为空    第三行位单号     第四行以及以后为记录
	{
			var colnumArr=rowArr[i].split("[td]");
			if(colnumArr.length>2)
			resultJson.records.push({date:colnumArr[1]+" "+colnumArr[2],track:colnumArr[3]});
	}
	return  resultJson ;
}
function getStoInfo_json(id){
	var resxml=ajaxSyncCall("oo.jsp?charset=GB2312&url=http://115.238.55.94:8081/result.asp?wen="+id);
	resxml=resxml.match(/<table[\s\S]*<\/table>/g)[0];
	resxml=resxml.replace(/[\n\s(&nbsp;)]/g,"");
 
	resxml=resxml.replace(/<tr[^>]*>/g,"[tr]");
	resxml=resxml.replace(/<t[d,h][^>]*>/g,"[td]");
	resxml=resxml.replace(/<[^>]+>/g,"");
	
 	var resultJson={billno:"",records:[]};
	var  rowArr=resxml.split("[tr]");
	//处理单号
	resultJson.billno=rowArr[1].replace(/[(\[td\]),(:),(跟踪记录)]/g,"");
	if(rowArr.length<=3){
		return {err:"SORRY,单号["+id+"]的信息未找到，请咨询电话：0571-82122222"};
	}
	for(var i=2;i<rowArr.length-1;i++)//第一行第二行为空    第三行位单号     第四行以及以后为记录
	{
			var colnumArr=rowArr[i].split("[td]");
			resultJson.records.push({date:colnumArr[1] ,track:colnumArr[2]});
	}
	return  resultJson ;
}
function getYtoInfo_json(id,code){
	var resxml=ajaxSyncCall("oo.jsp?charset=GB2312&url=http://www.yto.net.cn/service/pl_sql.aspx?NumberText="+id+"$CodeText="+code);
	resxml=resxml.match(/<span id="Label1">[\s\S]*<\/span>/g)[0];
	resxml=resxml.replace(/[\n\s(&nbsp;)]/g,"");
 
	resxml=resxml.replace(/<tr[^>]*>/g,"[tr]");
	resxml=resxml.replace(/<t[d,h][^>]*>/g,"[td]");
	resxml=resxml.replace(/<[^>]+>/g,"");
	
 	var resultJson={billno:"",records:[]};
	var  rowArr=resxml.split("[tr]");
	//处理单号
	resultJson.billno=id;
//	resultJson.billno=rowArr[1].replace(/[(\[td\]),(:),(跟踪记录)]/g,"");
	if(rowArr.length<=3){
		return {err:"SORRY,单号["+id+"]的信息未找到，请咨询电话： 021-69777888"};
	}
	for(var i=3;i<rowArr.length;i++)//第一行第二行为空    第三行位单号     第四行以及以后为记录
	{
			var colnumArr=rowArr[i].split("[td]");
			resultJson.records.push({date:colnumArr[2],track:colnumArr[3]});
	}
	return  resultJson ;
}
function getSfInfo_json(id,code){
	//var resxml=ajaxSyncCall("oo.jsp?charset=UTF-8&url=http://www.sf-express.com/tabid/521/Default.aspx?TrackList="+id+"$code="+code);
	//var ifm=document.getElementById("hideif");
	//ifm.src="http://www.sf-express.com/tabid/521/Default.aspx?TrackList="+id+"&code="+code;
	alert("暂不支持");return null;
	
	resxml=resxml.match(/监控记录[\s\S]*<\/table>/g)[0];
	resxml=resxml.replace(/[\n\s(&nbsp;)]/g,"");
 
	resxml=resxml.replace(/<tr[^>]*>/g,"[tr]");
	resxml=resxml.replace(/<t[d,h][^>]*>/g,"[td]");
	resxml=resxml.replace(/<[^>]+>/g,"");
	alert(resxml); return ;
 	var resultJson={billno:"",records:[]};
	var  rowArr=resxml.split("[tr]");
	//处理单号
	resultJson.billno=id;
//	resultJson.billno=rowArr[1].replace(/[(\[td\]),(:),(跟踪记录)]/g,"");
	if(rowArr.length<=3){
		return {err:"SORRY,单号["+id+"]的信息未找到，请咨询电话： 021-69777888"};
	}
	for(var i=3;i<rowArr.length;i++)//第一行第二行为空    第三行位单号     第四行以及以后为记录
	{
			var colnumArr=rowArr[i].split("[td]");
			resultJson.records.push({date:colnumArr[2],track:colnumArr[3]});
	}
	return  resultJson ;
}